//
//  PublishRenSubCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/26.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "PublishRenSubCell.h"
@interface PublishRenSubCell ()
/** <#note#> */
@property (nonatomic, weak) UIButton *iconBtn;


@property (nonatomic, weak) UIButton *colseBtn;

@end
@implementation PublishRenSubCell
- (UIButton *)iconBtn{
    if (!_iconBtn) {
        
        UIButton *temp = [UIButton buttonWithType:UIButtonTypeCustom];
        
        _iconBtn = temp;
        
        _iconBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        
        [self.contentView addSubview:self.iconBtn];
        
        
    }
    return _iconBtn;
}


- (UIButton *)colseBtn{
    if (!_colseBtn) {
        UIButton *temp = [UIButton buttonWithType:UIButtonTypeCustom];
        
        _colseBtn = temp;
        
        [_colseBtn setImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
        
        
        [self.contentView addSubview:self.colseBtn];
        
    }
    return _colseBtn;
}



- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        [self.iconBtn addTarget:self action:@selector(addBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        [self.colseBtn addTarget:self action:@selector(deleBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    return self;
}

- (void)setImage:(UIImage *)image{
    
    _image = image;
    
    if (_image != nil) {
        
        [self.iconBtn setBackgroundImage:nil forState:UIControlStateNormal];
        [self.iconBtn setBackgroundImage:nil forState:UIControlStateHighlighted];
        [self.iconBtn setImage:_image forState:UIControlStateNormal];
        [self.iconBtn setImage:_image forState:UIControlStateHighlighted];
        
        self.colseBtn.hidden = NO;
        
    } else {
        
        [self.iconBtn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add"] forState:UIControlStateNormal];
        [self.iconBtn setBackgroundImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateHighlighted];
        [self.iconBtn setImage:nil forState:UIControlStateNormal];
        [self.iconBtn setImage:nil forState:UIControlStateHighlighted];
        
        self.colseBtn.hidden = YES;
        
        
    }
    
    
    
    
}


- (void)addBtnDidClick{
    
    if ([self.delegate respondsToSelector:@selector(photoCollectionCellAddBtnDidClick:)]) {
        
        [self.delegate photoCollectionCellAddBtnDidClick:self.index];
        
    }
    
    
}



- (void)deleBtnDidClick{
    
    if ([self.delegate respondsToSelector:@selector(photoCollectionDeleBtnDidClick:)]) {
        
        [self.delegate photoCollectionDeleBtnDidClick:self.index];
        
    }
    
    
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.iconBtn.frame = self.bounds;
    
    self.colseBtn.frame = CGRectMake(self.bounds.size.width - 35, 0, 35, 35);
    
}
@end
